package com.pda.common;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;
import com.apkfuns.logutils.LogLevel;
import com.apkfuns.logutils.LogUtils;
import com.pda.common.dao.DaoMaster;
import com.pda.common.dao.DaoSession;
import com.pda.common.tools.MyCatchException;
import com.pda.common.tools.SharedPreferencesManger;
import com.pda.common.tools.VoiceUtils;
import io.reactivex.plugins.RxJavaPlugins;
import me.jessyan.autosize.AutoSize;
import me.jessyan.autosize.AutoSizeConfig;
import static io.reactivex.internal.functions.Functions.emptyConsumer;

public class PdaApp extends Application {
    public static final String TAG = "PdaApp";
    public static DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
//        MyCatchException mException= MyCatchException.getInstance();
//        mException.init(getApplicationContext());
        LogUtils.getLogConfig()
                .configAllowLog(true)  // 是否在Logcat显示日志
                .configTagPrefix("PDA") // 配置统一的TAG 前缀
                //.configFormatTag("%d{HH:mm:ss:SSS} %t %c{-5}") // 首行显示信息(可配置日期，线程等等)
                .configShowBorders(true) // 是否显示边框
                .configLevel(LogLevel.TYPE_VERBOSE); // 配置可展示日志等级
        SharedPreferencesManger.init(getApplicationContext());
        AutoSize.initCompatMultiProcess(this);
        AutoSizeConfig.getInstance().getExternalAdaptManager();
//                .addExternalAdaptInfoOfActivity(PictureSelectorActivity.class, new ExternalAdaptInfo(true, 400))
//                .addExternalAdaptInfoOfActivity(PicturePreviewActivity.class, new ExternalAdaptInfo(true, 400))
//                .addExternalAdaptInfoOfActivity(PictureExternalPreviewActivity.class, new ExternalAdaptInfo(true, 400));
        setupDatabase();
        RxJavaPlugins.setErrorHandler(emptyConsumer());
        VoiceUtils.initSound(this);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    public void setupDatabase() {
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "pda.db", null);
        SQLiteDatabase db = helper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }
}
